<template>
    <div class="particulars">
        <v-detail :detailData="inputData" :inputConfig="inputConfig" :rules="rules" ref="input"></v-detail>
    </div>
</template>

<script>
import detail from "commons/Detail";
import baseMixin from "@/mixins/BaseMixin";

export default {
    name: "particulars",
    mixins: [baseMixin],
    props: {
        inputData: {
            type: Object
        }
    },
    data() {
        return {
            flag: false,
            rules: {
                code: [
                    {required: true, validator: this.code, trigger: 'blur'},
                ],
                rank: [
                    {required: true, validator: this.rank, trigger: 'blur'},
                ],
                description: [
                    {required: true, validator: this.description, trigger: 'blur'},
                ],
            },
        }
    },
    computed: {
        inputConfig() {
            return [
                [
                    {
                        type: "input",
                        label: this.$t('config.freezeCode'),
                        props: "code",
                        disabled: this.flag
                    },
                    {
                        type: "input",
                        label: this.$t('config.rank'),
                        props: "rank",
                    },
                    {
                        type: "textarea",
                        label: this.$t('config.freezeDesc'),
                        props: "description",
                    }
                ]
            ]
        }
    },
    methods: {
        description(rule, value, callback) {
            if (value === '') {
                this.$message.error(this.$inputEmptyMes('config.freezeDesc'))
                callback(new Error());
            } else {
                callback();

            }
        },
        code(rule, value, callback) {
            if (value === '') {
                this.$message.error(this.$inputEmptyMes('config.freezeCode'))
                callback(new Error());
            } else {
                var re = /^[^\u4e00-\u9fa5]{0,}$/;
                let te = value;
                let flag = re.test(te)
                if (flag) {
                    callback();
                } else {
                    this.$message.error(this.$tj("config.freezeCode",'app.dataIsNotZh'));
                    this.inputData[rule.field] = ""
                    callback(new Error());
                }
            }
        },
        rank(rule, value, callback) {
            if (value === '') {
                this.$message.error(this.$inputEmptyMes('config.rank'))
                callback(new Error());
            } else {
                var re = /^[0-9]*$/;
                let te = value;
                let flag = re.test(te)
                if (flag) {
                    if (value < 0) {
                        this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
                        this.inputData[rule.field] = ""
                        callback(new Error());
                    } else {
                        callback();
                    }
                } else {
                    this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
                    this.inputData[rule.field] = ""
                    callback(new Error());
                }
            }
        },
    },
    mounted() {
        if (Object.keys(this.$store.state.skip).length !== 0) {
            let data = this.$store.state.skip;
            if (data.newFlag) {
                this.flag = false;
            } else {
                this.flag = true;
            }
        } else if (this.$store.state.newFlag) {
            this.flag = false;
        } else {
            this.flag = true;
        }
    },
    components: {
        "v-detail": detail,
    },

}
</script>

<style scoped>

</style>
